<?php
/**
 * 
 * @author huangjian E-mail:870596179@qq.com
 * @version 创建时间：2016年10月26日 下午2:30:57 
 * 类说明
 */
class MailTimeAction extends BaseAction{
	/**
	 * @authority 浏览
	 */
	public function index(){
		$this->display('index');
	}
	
	//列表
	public function getAllData(){
		$Model = M($this->getActionName());
		$map = $this->loadSeachCondition();
		$map['flag'] = 1;
		$total = $Model->where($map)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		$data = $Model->where($map)->limit($page->firstRow,$page->listRows)->order($page->sort)->select();
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}
	
	/**
	 * 组装条件
	 * @return multitype:multitype:string
	 */
	public function loadSeachCondition(){
		$map = array();
		if(!empty($_GET['field'])){
			$map['field'] = array("like","%".$_GET['field']."%");
		}
		return $map;
	}
	
	/**
	 * 逻辑删除
	 */
	public function logicDel(){
		$Model = M($this->getActionName());
		$where['flag'] = 1;
		$count = $Model->where($where)->count();
		if($count < 2){
			$this->ajaxReturn(0,"删除失败！至少保留一个配送时间段！",0);
		}else{
			if (!empty($Model)) {
				$pk = $Model->getPk();
				$id = $_REQUEST[$pk];
				if (isset($id)) {
					$condition = array($pk => array('in', explode(',', $id)));
					if (false !== $Model->where($condition)->setField('flag',2)) {
						$this->ajaxReturn(1,L('ADMIN_DELETE_SUCCESS'),1);
					} else {
						$this->ajaxReturn(0,L('ADMIN_DELETE_ERROR'),0);
					}
				} else {
					$this->ajaxReturn(0,L('ADMIN_DELETE_ERROR'),0);
				}
			}
		}
		
	}
}